﻿using System;
using System.Collections.Generic;
using PersonaLibrary.Data;
using PersonaLibrary.Search;

namespace PersonaLibrary.ViewModel.OrganizationsViewModel
{
	internal class OrganizationSearchVM: SearchViewModel<Data.Organization>
	{
		protected override List<BaseSearchProperty> CreateProeprties()
		{
			List<BaseSearchProperty> properties = new List<BaseSearchProperty>
															 {
																 new StringSearchProperty(Parametr)
																	 {PropertyName = "Name", DisplayName = "Название"},
																 new StringSearchProperty(Parametr)
																	 {
																		 PropertyName = "Category",
																		 DisplayName = "Категория"
																	 },
																 new StringSearchProperty(Parametr)
																	 {
																		 PropertyName = "Ownership",
																		 DisplayName = "Форма собственности"
																	 },
																 new StringSearchProperty(Parametr)
																	 {
																		 PropertyName = "Legaladdress",
																		 DisplayName = "Юридический адрес"
																	 },
																 new StringSearchProperty(Parametr)
																	 {
																		 PropertyName = "Legalphone",
																		 DisplayName = "Телефон организации"
																	 },
																 new StringSearchProperty(Parametr)
																	 {PropertyName = "Site", DisplayName = "Сайт"},
																new CollectionSearchProperty<Department>(Parametr)
																	 {PropertyName = "Departments", DisplayName = "Отдел", CollectionItemProperty = "Name"}
															 };

			return properties;
		}

		protected override void OnExpresseionCreated(System.Linq.Expressions.LambdaExpression expression)
		{
			Func<BaseEntity, bool> filter = delegate(BaseEntity ent)
												{
													return (bool) expression.Compile().DynamicInvoke(new object[] {ent});
												};

			CurrentApplication.Filter = new Filter(GetType().Name, typeof(Organization))
			                            	{
			                            		DisplayName = "Поиск по организациям",
			                            		FuncFilter = filter,
			                            		SubFilter =
			                            			new AlphabetFilter(typeof (Organization), true)
			                            				{DisplayName = "Поиск по организациям"}
			                            	};
			base.OnExpresseionCreated(expression);
		}
	}
}
